<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head>
    <th:block th:include="include :: header('出库作业管理')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="col-sm-12 search-collapse">
        <form id="user-form">
            <div class="select-list">
                <ul>
                    <input name="inOut" type="text" value="9" hidden="hidden">
                    <!--                    <li>-->
                    <!--                        <label class="is-required">仓库：</label>-->
                    <!--                        <select id="warehouseId" name="warehouseId" th:with="type=${session.warehouse}">-->
                    <!--                            &lt;!&ndash;								<option   th:value="${session.warehouseId}" th:text="${@dict.getDictLabel('${session.warehouseId}')}"></option>&ndash;&gt;-->
                    <!--                            <option th:each="dict : ${type}" th:text="${dict.warehouseName}" th:value="${dict.warehouseId}"></option>-->
                    <!--                        </select>-->
                    <!--                    </li>-->

                    <li>
                        <label>仓库：</label>
                        <select name="warehouseId" th:with="type=${@dict.getType('is_house')}" required>
                            <option value="">请选择</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
                    </li>

                    <li>
                        <label>下发单号：</label><input type="text" name="supplierId"/>
                    </li>

                    <li>
                        <label>作业状态：</label>
                        <select name="status" th:with="type=${@dict.getType('job_status')}" required>
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
                    </li>
                    <li>
                        <label>任务号：</label><input type="text" name="taskNo"/>
                    </li>
                    <li>
                        <label>巷道：</label><input type="text" name="roadwayId"/>
                    </li>
                    <li>
                        <label>托盘条码：</label><input type="text" name="trayCode"/>
                    </li>
                    <li>
                        <label>物资编码：</label><input type="text" name="productId"/>
                    </li>
                    <li>
                        <label>出库类型：</label>
                        <select name="inOrOut" th:with="type=${@dict.getType('outjob')}" required>
                            <option value="">请选择</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
                    </li>
                    <li>
                        <label>创建时间：</label><input type="text" class="time-input" data-type="datetime" placeholder="请单击选择开始时间：" name="startTime" id="startTime"/>---
                        <input type="text" class="time-input" data-type="datetime" placeholder="请单击选择结束时间：" name="finishTime" id="finishTime"/>
                    </li>

                    <li>
                        <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                class="fa fa-search"></i>&nbsp;搜索</a>
                        <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                class="fa fa-refresh"></i>&nbsp;重置</a>
                    </li>
                </ul>
            </div>
        </form>
    </div>
    <div class="btn-group-sm" id="toolbar" role="group">
        <a class="btn btn-success" onclick="handFinish()" >
            <i class="fa fa-plus"></i> 手动完成
        </a>
        <a class="btn btn-danger" onclick="handInvalid()">
            <i class="fa fa-trash-o"></i> 手动作废
        </a>
        <a class="btn btn-danger" onclick="updateExecu()">
            <i class="fa fa-trash-o"></i> 优先一点
        </a>
        拣选台
        <select id="jxt">
            <option value="">请选择</option>
            <option value="1">1号拣选台</option>
            <option value="2">2号拣选台</option>
            <option value="3">3号拣选台</option>
            <option value="4">4号拣选台</option>
        </select>
        <a class="btn btn-danger" onclick="updateOutId()">
            <i class="fa fa-trash-o"></i> 修改拣选台
        </a>



    </div>

    <div  id="div1" class="col-sm-12 select-table table-bordered">
        <table id="bootstrap-table"></table>
    </div>
    <div  class="col-sm-8 select-table">
        <table id="bootstrap-table2" data-mobile-responsive="true"></table>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('mydo:mydojob:edit')}]];
    var removeFlag = [[${@permission.hasPermi('mydo:mydojob:remove')}]];
    var job_status = [[${@dict.getType('job_status')}]];
    // var outjob = [[${@dict.getType('in_or_out')}]];
    var outjob = [[${@dict.getType('outjob')}]];
    var stackingId = [[${@dict.getType('stacking_id')}]]
    var product_status = [[${@dict.getType('product_status')}]];
    var isHouse = [[${@dict.getType('is_house')}]];
    var jobExeDatas = [[${@dict.getType('job_execution_in')}]];

    var prefix = ctx + "out/mydojob"

    //子表
    var options2 = {
        updateUrl: ctx + "out/stockindetail/edit/{id}",
        removeUrl: ctx + "out/jobdetail/remove",
        search: false,
        showRefresh: false,
        showColumns: false,
        minimumCountColumns: 2,
        clickToSelect: true,//是否启用点击选中行
        // height: $("#div2").height() / 1,
        sortName: "assignNum",
        sortOrder: "desc",
        modalName: "入库单据子表",
        method: 'post',

        striped: true, //是否显示行间隔色
        pagination: true,//显示分页
        sidePagination: "client",
        pageNumber: 1,
        pageSize: 15,
        pageList: [10, 25],
        columns:
            [{
                checkbox: true,
            },
                {
                    field: 'jobDetailId',
                    title: '子表编号',
                    align: 'center'
                },
                {
                    field: 'jobId',
                    title: '主表编号',
                    align: 'center',
                    visible: false
                },
                {
                    field: 'inOrOutDId',
                    title: 'WCS子单号',
                    align: 'center',
                },
                {
                    field: 'station',
                    title: 'WMS下发单号',
                    align: 'center',
                },
                {
                    field: 'productId',
                    title: '物品编号',
                    align: 'center',
                },
                {
                    field: 'productName',
                    title: '物品名称',
                    align: 'center',
                },
                {
                    field: 'lotNo',
                    title: '批号',
                    align: 'center'
                },
                {
                    field: 'inDate',
                    title: '入库时间',
                    align: 'center'
                },
                {
                    field: 'stockId',
                    title: '库存编号',
                    align: 'center'
                },
                /*{
                    field: 'productStatus',
                    title: '物品状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(product_status, value);
                    }
                },*/
                /* {
                     field: 'printDate',
                     title: '生产时间',
                     align: 'center',
                 },*/
                {
                    field: 'grade',
                    title: '客户',
                    align: 'center'
                },{
                field: 'spec',
                title: '供应商',
                align: 'center'
            },
                {
                    field: 'outQuantity',
                    title: '出库数量',
                    align: 'center'
                }
            ],
        onLoadSuccess(data) {
            switch (data.code) {
                case  500:
                    options2.url = "";
                    $('#bootstrap-table2').bootstrapTable("removeAll")
                    $.modal.alertWarning("查询出错！");
                    break;
                default:
                    break;
            }
        },
    }


    $('#bootstrap-table2').bootstrapTable(options2)
    //主表
    var options = {
        url: "/mydo/mydojobout/list",
        detailView: false,//父子表
        search: false,
        showRefresh: true,
        singleSelect:true,
        showColumns: true,
        // height: $("#div1").height() / 1,
        minimumCountColumns: 2,
        clickToSelect: true,//是否启用点击选中行
        createUrl: prefix + "/add",
        updateUrl: prefix + "/edit/{id}",
        removeUrl: prefix + "/remove",
        handFinishUrl: prefix + "/handFinish",
        handInvalidUrl: prefix + "/handInvalid",
        changeJobStatusUrl: prefix + "/changeJobStatus",
        sortName: "createTime",
        sortOrder: "desc",
        modalName: "入库作业信息",
        columns: [{
            checkbox: true
        },
            {
                field: 'jobId',
                title: '作业编号',
                align: 'center'
            },
            {
                field: 'status',
                title: '作业状态',
                align: 'center',
                formatter: function (value, row, index) {
                    return $.table.selectDictLabel(job_status, value);
                }
            },

            {
                field: 'taskNo',
                title: '任务号',
                align: 'center'
            },
            {
                field: 'exitId',
                title: '托盘库出口',
                align: 'center'
            },
            {
                field: 'outId',
                title: '拣选台/出口',
                align: 'center'
            },
            {
                field: 'roadwayId',
                title: '巷道',
                align: 'center'
            },
            {
                field: 'cargoSpaceId',
                title: '货位',
                align: 'center',
                visible: true
            },
            {
                field: 'lineId',
                title: '货位',
                align: 'center'
            },
            {
                field: 'trayCode',
                title: '托盘码',
                align: 'center',
            },
            {
                field: 'workshopId',
                title: '派单人',
                align: 'center'
            },
            {
                field: 'faultFlag',
                title: '上位下发单号',
                align: 'center'
            },
            {
                field: 'priority',
                title: '优先级',
                align: 'center'
            },
            {
                field: 'executionPhase',
                title: '执行阶段',
                align: 'center',
                formatter: function (value, row, index) {
                    return $.table.selectDictLabel(jobExeDatas, value);
                }
            },
            {
                field: 'inOrOut',
                title: '出库类型',
                align: 'center',
                formatter: function (value, row, index) {
                    return $.table.selectDictLabel(outjob, value);
                }
            },
            {
                field: 'srcSite',
                title: '原站点',
                align: 'center'
            },
            {
                field: 'tarSite',
                title: '目标站点',
                align: 'center'
            },
            {
                field: 'createTime',
                title: '创建时间',
                align: 'center'
            },
            {
                field: 'startTime',
                title: '开始时间',
                align: 'center'
            },
            {
                field: 'finishTime',
                title: '完成时间',
                align: 'center'
            },
            {
                field: 'warehouseId',
                title: '仓库',
                align: 'center',
                formatter: function (value, index, row){
                    return $.table.selectDictLabel(isHouse, value);
                }
            }
            // {
            //     field: 'stockSource',
            //     title: '库存来源'
            // }
        ],
        //双击显示主表
        onClickRow: function (t, e) {
            options2.url = ctx + "mydo/detail/list?jobId=" + t.jobId + "&status=" + t.status;
            $('#bootstrap-table2').bootstrapTable("refresh", options2)
        },
        onLoadSuccess(data) {
            switch (data.code) {
                case  500:
                    options2.url = "";
                    $('#bootstrap-table').bootstrapTable("removeAll");
                    $('#bootstrap-table2').bootstrapTable("removeAll");
                    $.modal.alertWarning("查询出错！");
                    break;
                default:
                    $('#bootstrap-table2').bootstrapTable("removeAll");
                    break;
            }
        },
    };
    $.table.init(options);


    function handFinish() {
        var checkedItems = $('#bootstrap-table').bootstrapTable('getSelections');
        if(checkedItems[0].status!=3){
            $.modal.alertError("只能完成正在执行的作业");
            return;
        }
        if(checkedItems[0].inOrOut == '14'){
            $.modal.alertError("不可操作盘点出库作业！");
            return;
        }
        if(checkedItems[0].length == 0){
            $.modal.alertError("请选择一条记录！");
            return;
        }
        if(checkedItems[0].length > 1){
            $.modal.alertError("只允许选择一条记录！");
            return;
        }
        $.post("/mydo/mydojobout/handFinish", {
            trayCode: checkedItems[0].trayCode,
            inOrOut: checkedItems[0].inOrOut
        }, function (result) {
            if (result.code == 0){
                $.modal.alertSuccess(result.msg);
                $("#bootstrap-table").bootstrapTable('refresh');
            } else {
                $.modal.alertError(result.msg);
            }
        })
    }

    function backkick() {
        $.post("/apis/backOutOrder", {
        }, function (result) {
            if (result.code == 0){
                $.modal.alertSuccess(result.msg);
                $("#bootstrap-table").bootstrapTable('refresh');
            } else {
                $.modal.alertError(result.msg);
            }
        })
    }


    function handInvalid() {
        var checkedItems = $('#bootstrap-table').bootstrapTable('getSelections');
        if(checkedItems[0].status!=1){
            $.modal.alertError("只能作废未执行的作业!");
            return;
        }
        $.post("/mydo/mydojobout/handInvalid", {
            ids: checkedItems[0].jobId
        }, function (result) {
            if (result.code == 0){
                $.modal.alertSuccess(result.msg);
                $("#bootstrap-table").bootstrapTable('refresh');
            } else {
                $.modal.alertError(result.msg);
            }
        })
    }

    function updateExecu() {
        var checkedItems = $('#bootstrap-table').bootstrapTable('getSelections');
        if(checkedItems[0].status!=1){
            $.modal.alertError("只能调整未执行的作业!");
            return;
        }
        $.post("/mydo/mydojobout/updateExecu", {
            ids: checkedItems[0].jobId
        }, function (result) {
            if (result.code == 0){
                $.modal.alertSuccess(result.msg);
                $("#bootstrap-table").bootstrapTable('refresh');
            } else {
                $.modal.alertError(result.msg);
            }
        })
    }

    function updateOutId() {
        var checkedItems = $('#bootstrap-table').bootstrapTable('getSelections');
        if(checkedItems[0].status!=1){
            $.modal.alertError("只能调整未执行的作业!");
            return;
        }
        var jxt=$("#jxt").val();
        if(jxt==''||jxt==null){
            $.modal.alertError("请选择拣选台！")
            return;
        }
        $.post("/mydo/mydojobout/updateOutId", {
            ids: checkedItems[0].jobId,
            outId:  jxt
        }, function (result) {
            if (result.code == 0){
                $.modal.alertSuccess(result.msg);
                $("#bootstrap-table").bootstrapTable('refresh');
            } else {
                $.modal.alertError(result.msg);
            }
        })
    }


</script>
</body>
</html>